<?php 
namespace Org\Curl;
class Curl{
	public function getCurl($url,$https=true,$method='get',$data=null){
        //1. 初始化
        $ch = curl_init();
        //2.设置参数
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//只获取页面内容,但不输出 return transfer
        if($https){
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        }
        if($method=='post'){
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        }
        //3.调用接口
        $res = curl_exec($ch);
        //4.关闭curl
        curl_close($ch);

        if(curl_errno($ch)){
            //请求失败,返回错误信息
            return curl_error($ch);
        }
        return $res;
    }
}

?>